package com.aw.guiguzi.module.common

import android.os.SystemClock
import android.text.SpannableString
import android.text.method.DigitsKeyListener
import android.view.View
import android.widget.EditText
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.RadioButton
import android.widget.RadioGroup
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.aw.baselib.base.AwBaseEvent
import com.aw.baselib.base.AwMvpActivity
import com.aw.baselib.base.AwMvpBindingActivity
import com.aw.baselib.bean.rx.EventReLoginType
import com.aw.baselib.constants.Extras
import com.aw.baselib.util.AwAppUtils
import com.aw.baselib.util.AwAppUtils.TYPE_VERSION
import com.aw.baselib.util.AwConvertUtil
import com.aw.baselib.util.AwDataUtil
import com.aw.baselib.util.AwDisplayUtil
import com.aw.baselib.util.AwEditTextListener
import com.aw.baselib.util.AwJsonUtil
import com.aw.baselib.util.AwLog
import com.aw.baselib.util.AwRecyclerViewUtil
import com.aw.baselib.util.AwVersionUtil
import com.aw.baselib.util.update.AwUpdateUtil
import com.aw.baselib.util.update.UpdateBean
import com.aw.guiguzi.BuildConfig
import com.aw.guiguzi.R
import com.aw.guiguzi.adapter.MainCalAnalaysisAdapter
import com.aw.guiguzi.adapter.MainCalAnalaysisCombinationAdapter
import com.aw.guiguzi.adapter.MainCalSuggestAdapter
import com.aw.guiguzi.adapter.MainResultNumAdapter
import com.aw.guiguzi.base.MyApp
import com.aw.guiguzi.bean.AnalysisCombinationItemBean
import com.aw.guiguzi.bean.AnalysisDataResultBean
import com.aw.guiguzi.bean.CalResultBean
import com.aw.guiguzi.bean.CalSuggestItemBean
import com.aw.guiguzi.bean.NumEncloseBean
import com.aw.guiguzi.bean.NumHandleInputResultBean
import com.aw.guiguzi.bean.NumItemBean
import com.aw.guiguzi.bean.PGYUpdateBean
import com.aw.guiguzi.constants.MyConstant
import com.aw.guiguzi.databinding.ActivityMainBinding
import com.aw.guiguzi.enums.CombinationTagEnums
import com.aw.guiguzi.enums.TrendTagEnums
import com.aw.guiguzi.event.EventLocalReLoginType
import com.aw.guiguzi.event.EventRefreshCalResultType
import com.aw.guiguzi.event.EventRefreshMsgUnreadCountType
import com.aw.guiguzi.event.EventRefreshUserInfoType
import com.aw.guiguzi.module.common.presenters.MainPresent
import com.aw.guiguzi.module.common.views.MainView
import com.aw.guiguzi.module.manager.ManagerActivity
import com.aw.guiguzi.module.setting.SettingActivity
import com.aw.guiguzi.module.setting.SettingUiActivity
import com.aw.guiguzi.util.AppCacheUtil
import com.aw.guiguzi.util.AppCaseUtil.showCase
import com.aw.guiguzi.util.AppPopupWindowUtil.showMainCalAnalaysisPopupWindow
import com.aw.guiguzi.util.AppPopupWindowUtil.showNum3SingleCheckPopupWindow
import com.aw.guiguzi.util.AppPopupWindowUtil.showNum7SingleCheckPopupWindow
import com.aw.guiguzi.util.AppPopupWindowUtil.showNumEnclosePopupWindow
import com.aw.guiguzi.util.AppPopupWindowUtil.showNumHandleInputPopupWindow
import com.aw.guiguzi.util.AppPopupWindowUtil.showNumImgPopupWindow
import com.aw.guiguzi.util.AppPopupWindowUtil.showNumPopupWindow
import com.aw.guiguzi.util.AppPopupWindowUtil.showNumSingleCheckPopupWindow
import com.aw.guiguzi.util.AppPopupWindowUtil.showNumSingleCheckRateAnalysisPopupWindow
import com.aw.guiguzi.util.AppUserUtil.isAdmin
import com.aw.guiguzi.util.AppUserUtil.nickname
import com.aw.guiguzi.util.AppUserUtil.saveToken
import com.aw.guiguzi.util.CalResultUtil.calResultCount
import com.aw.guiguzi.util.CalResultUtil.encloseList
import com.aw.guiguzi.util.CalResultUtil.generateNumList
import com.aw.guiguzi.util.CalResultUtil.imitateList
import com.aw.guiguzi.util.DataUtil
import com.aw.guiguzi.util.DataUtil.allNumEncloseList
import com.aw.guiguzi.util.DataUtil.allTrendList
import com.aw.guiguzi.util.DataUtil.combinationEnumsList
import com.aw.guiguzi.util.DataUtil.convertListToStr
import com.aw.guiguzi.util.DataUtil.countOccurrences
import com.aw.guiguzi.util.DataUtil.getAnalysisResultList
import com.aw.guiguzi.util.DataUtil.getBetterColor
import com.aw.guiguzi.util.DataUtil.getBetterTrends
import com.aw.guiguzi.util.DataUtil.getBigAndSmallNumStr
import com.aw.guiguzi.util.DataUtil.getBigNumCount
import com.aw.guiguzi.util.DataUtil.getColdNumList
import com.aw.guiguzi.util.DataUtil.getColorNumStr
import com.aw.guiguzi.util.DataUtil.getCombinationCount
import com.aw.guiguzi.util.DataUtil.getDashboardNumStr
import com.aw.guiguzi.util.DataUtil.getDesignatedNums
import com.aw.guiguzi.util.DataUtil.getEvenNumCount
import com.aw.guiguzi.util.DataUtil.getEveryJumpSmoothlyMaxCountStr
import com.aw.guiguzi.util.DataUtil.getHotNumStr
import com.aw.guiguzi.util.DataUtil.getJumpNumList
import com.aw.guiguzi.util.DataUtil.getMidEdgeNumStr
import com.aw.guiguzi.util.DataUtil.getNumList_red
import com.aw.guiguzi.util.DataUtil.getNumList_yellows
import com.aw.guiguzi.util.DataUtil.getSingleMaxCountStr
import com.aw.guiguzi.util.DataUtil.getSingularAndEvenNumStr
import com.aw.guiguzi.util.DataUtil.getSingularNumCount
import com.aw.guiguzi.util.DataUtil.getSmallNumCount
import com.aw.guiguzi.util.DataUtil.getTrendEnumsList
import com.aw.guiguzi.util.DataUtil.judgeGreater
import com.aw.guiguzi.util.DataUtil.judgeJumpSmoothlyMaxCountEndStr
import com.aw.guiguzi.util.DataUtil.matcherSearchText
import com.aw.guiguzi.util.MyFileUtil.allFileList
import com.aw.guiguzi.util.MyFileUtil.setContext
import com.aw.guiguzi.util.MyFileUtil.writeDefault
import com.aw.guiguzi.util.MyFileUtil.writeFile
import com.aw.guiguzi.util.ReLoginUtil.finishToLogin
import com.aw.guiguzi.util.ReLoginUtil.isAllowHandleReLogin
import com.aw.guiguzi.widgets.Num3SingleCheckPopupWindow
import com.aw.guiguzi.widgets.Num7SingleCheckPopupWindow
import com.aw.guiguzi.widgets.NumHandleInputPopupWindow
import com.aw.guiguzi.widgets.NumImgPopupWindow
import com.aw.guiguzi.widgets.NumPopupWindow
import com.aw.guiguzi.widgets.NumSingleCheckPopupWindow
import com.chad.library.adapter.base.BaseQuickAdapter
import com.pgyersdk.update.PgyUpdateManager
import com.pgyersdk.update.UpdateManagerListener
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import java.util.concurrent.TimeUnit

class MainActivity : AwMvpBindingActivity<MainPresent, ActivityMainBinding>(), MainView.View {

    /**
     * 总计投注次数, 总计银数量, 总计皮数量, 总计宝石数量, 总计胜场次数
     */
    private var totalLooperCount = 0
    private var totalSilverCount = 0
    private var totalSkinCount = 0
    private var totalGemstoneCount = 0
    private var totalWinCount = 0
    private val mHits = LongArray(2)
    private var mCurrentNumList: MutableList<Int> = ArrayList() //当前版面所有数字集合
    private var mCurrentNumOriginList: MutableList<Int> = ArrayList() //当前版面所有数字集合(不做截取处理的)
    private var mCalSuggestListLeft: MutableList<CalSuggestItemBean> =
        ArrayList() //各走势下轮可选顺跳集合(展示区左侧数据)
    private var mCalSuggestListRight: MutableList<CalSuggestItemBean> =
        ArrayList() //各走势下轮可选顺跳集合(展示区右侧数据)
    private var mBettingNumsList: MutableList<NumItemBean>? = ArrayList() //已投注的数字集合
    private var mEncloseNumsList: MutableList<NumEncloseBean> = ArrayList() //所有结果数字集合, 用于点击选择指定结果数字
    private var mAllCalAnalaysisCommonList: MutableList<CalSuggestItemBean> = ArrayList()
    private var mAllCalAnalaysisList: MutableList<CalSuggestItemBean?> = ArrayList()
    private var mAllCalAnalaysisCombinationList: MutableList<AnalysisCombinationItemBean> =
        ArrayList()
    private var mCalNums = "" //待分析数字字符串, 根据单选框动态生成
    private var mDisposableUserInfo: Disposable? = null
    private var mResultNumAdapter: MainResultNumAdapter? = null
    private var mCalSuggestAdapterLeft: MainCalSuggestAdapter? = null
    private var mCalSuggestAdapterRight: MainCalSuggestAdapter? = null
    private var mainCalAnalaysisAdapter: MainCalAnalaysisAdapter? = null
    private var mainCalAnalaysisAdapterCommon: MainCalAnalaysisAdapter? = null
    private var mCombinationAdapter: MainCalAnalaysisCombinationAdapter? = null
    private var isHasCustomJumpSmooth = false
    private var customScreenOutPre = 15
    override fun refreshByBus(type: AwBaseEvent) {
        super.refreshByBus(type)
        if (type is EventReLoginType) {
            if (isAllowHandleReLogin) {
                saveToken("")
                toClass(LoginActivity::class.java, true, Extras.params, "ReLogin")
            }
        } else if (type is EventLocalReLoginType) {
            finishToLogin(mActivity)
        } else if (type is EventRefreshCalResultType) {
            if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_ALL) {
                binding.rBtnLimitAll.isChecked = true
            } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT1) {
                binding.rBtnLimit1.isChecked = true
            } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT2) {
                binding.rBtnLimit2.isChecked = true
            }
            setText(binding.rBtnLimit1, "后" + AppCacheUtil.getAnalysisLengthCustom() + "位")
            setText(binding.rBtnLimit2, "后" + AppCacheUtil.getLimitStatisticsCountCustom() + "位")
            DataUtil.calIntervalNum = AppCacheUtil.getCalIntervalNum()
            handleAnalysisData()
        } else if (type is EventRefreshUserInfoType) {
            mPresenter!!.getUserInfo()
        }
    }

    override fun getViewBinding(): ActivityMainBinding {
        return ActivityMainBinding.inflate(mActivity.layoutInflater)
    }

    override fun createPresenter(): MainPresent {
        return MainPresent(this)
    }

    public override fun initView() {
        super.initView()
        if (isAdmin) {
            AwLog.d("isAdmin")
            //            setToolbarWithBackCustomImgAndRightTxtImg(AppUserUtil.getNickname(), R.drawable.icon_manager, "", R.drawable.icon_me,
            //                    () -> toClass(ManagerActivity.class, false), () -> toClass(SettingActivity.class, false));
            if (BuildConfig.DEBUG) {
                setToolbarWithBackCustomImgAndRightTxtImg("测试",
                    R.drawable.icon_manager,
                    "",
                    R.drawable.icon_me,
                    { toClass(ManagerActivity::class.java, false) }) {
                    toClass(
                        SettingActivity::class.java, false
                    )
                }
            } else {
                setToolbarWithBackCustomImgAndRightTxtImg(
                    nickname, R.drawable.icon_manager, "", R.drawable.icon_me,
                    { toClass(ManagerActivity::class.java, false) }) {
                    toClass(
                        SettingActivity::class.java, false
                    )
                }
            }
        } else {
            AwLog.d("!isAdmin")
            setToolbarHideLeftWithRightImg(nickname, R.drawable.icon_me) {
                toClass(
                    SettingActivity::class.java, false
                )
            }
        }
    }

    public override fun initData() {
        super.initData()
        mPresenter!!.getUserInfo()
        setContext(mActivity)
        writeDefault(true)
        val digists = "0123456789\n"
        binding.etCurrentNums?.keyListener = DigitsKeyListener.getInstance(digists)
        MyApp.mAllBettingNumsList = generateNumList()
        MyApp.mAllNumEncloseList = encloseList
        MyApp.mAllNumImitateList = imitateList.toMutableList()
        startLoopUnreadMsg()

        //每次启动后, 遍历本地所有日志文件, 检测上传当日之前的文件，上传成功后执行自动删除, 历史数据仅展示当天的日志
        val fileList: List<String?> = allFileList
        if (!AwDataUtil.isEmpty(fileList)) {
            for (filePath in fileList) {
                mPresenter!!.uploadFile(filePath)
            }
        } else {
            AwLog.d("当日之前日志已清空")
            writeFile("{Local journal Empty.}")
        }
        checkAppUpdate(true)
        mPresenter!!.getMsgUnreadCount()
        mResultNumAdapter = MainResultNumAdapter()
        AwRecyclerViewUtil.setRecyclerViewGridlayout(
            mActivity,
            binding.rcvData,
            mResultNumAdapter,
            10,
            AwDisplayUtil.dip2px(mActivity, 5f)
        )
        mEncloseNumsList = allNumEncloseList
        mResultNumAdapter!!.addAllData(mEncloseNumsList)
        mCalSuggestAdapterLeft = MainCalSuggestAdapter()
        AwRecyclerViewUtil.setRecyclerViewLinearlayout(
            mActivity,
            binding.rcvDataSuggestLeft,
            mCalSuggestAdapterLeft,
            false
        )
        mCalSuggestAdapterRight = MainCalSuggestAdapter()
        AwRecyclerViewUtil.setRecyclerViewLinearlayout(
            mActivity,
            binding.rcvDataSuggestRight,
            mCalSuggestAdapterRight,
            false
        )
        mainCalAnalaysisAdapterCommon = MainCalAnalaysisAdapter()
        AwRecyclerViewUtil.setRecyclerViewLinearlayout(
            mActivity,
            binding.rcvDataAnalaysisCommon,
            mainCalAnalaysisAdapterCommon,
            false
        )
        mainCalAnalaysisAdapter = MainCalAnalaysisAdapter()
        AwRecyclerViewUtil.setRecyclerViewLinearlayout(
            mActivity,
            binding.rcvDataAnalaysis,
            mainCalAnalaysisAdapter,
            false
        )
        mCombinationAdapter = MainCalAnalaysisCombinationAdapter()
        AwRecyclerViewUtil.setRecyclerViewLinearlayout(
            mActivity,
            binding.rcvDataAnalaysisCombination,
            mCombinationAdapter,
            false
        )
        if (AppCacheUtil.isAutoFillHint() && !AwDataUtil.isEmpty(AppCacheUtil.getLastNums())) {
            showDialogCustomLeftAndRight("是否自动填充最后缓存的面板数据？", "取消", "确认",
                { v: View? -> checkShowHelpCase() }) { v: View? ->
                setText(binding.etCurrentNums, AppCacheUtil.getLastNums())
                checkShowHelpCase()
            }
        } else {
            checkShowHelpCase()
        }
    }

    public override fun initListener() {
        super.initListener()
        findViewById<View>(R.id.iv_uiAnalaysis).setOnClickListener { v: View? ->
//            if(!CommonUtil.isAllow()) {
//                return;
//            }
            showMainCalAnalaysisPopupWindow(mActivity, findViewById(R.id.iv_uiAnalaysis))
        }
        binding.rgLimitLength?.setOnCheckedChangeListener { group: RadioGroup?, checkedId: Int ->
            when (checkedId) {
                R.id.rBtn_limitAll -> AppCacheUtil.setLimitType(
                    MyConstant.SWITCH_ALL
                )

                R.id.rBtn_limit1 -> AppCacheUtil.setLimitType(MyConstant.SWITCH_LIMIT1)
                R.id.rBtn_limit2 -> AppCacheUtil.setLimitType(MyConstant.SWITCH_LIMIT2)
            }
            handleAnalysisData()
        }
        mResultNumAdapter!!.setOnItemClickListener { adapter: BaseQuickAdapter<*, *>, view: View?, position: Int ->
            val checkedResultNumBean = adapter.getItem(position) as NumEncloseBean?
            if (AppCacheUtil.isResultNumCheckHint()) {
                showDialogWithCancelDismiss("确认选择数字：" + checkedResultNumBean!!.resultNumber + "吗？") { v: View? ->
                    setResultView(checkedResultNumBean)
                    if (AwDataUtil.isEmpty(mBettingNumsList)) {
                        binding.etCurrentNums.append(checkedResultNumBean.resultNumber.toString())
                        return@showDialogWithCancelDismiss
                    }
                    val calResultBean =
                        calResultCount(mBettingNumsList!!, checkedResultNumBean.resultNumber)
                    showResult(calResultBean)
                }
            } else {
                setResultView(checkedResultNumBean)
                if (AwDataUtil.isEmpty(mBettingNumsList)) {
                    binding.etCurrentNums.append(checkedResultNumBean!!.resultNumber.toString())
                    return@setOnItemClickListener
                }
                val calResultBean =
                    calResultCount(mBettingNumsList!!, checkedResultNumBean!!.resultNumber)
                showResult(calResultBean)
            }
        }
        findViewById<View>(R.id.iv_toEncloseSpecialNum).setOnClickListener { v: View? ->
//            if(!CommonUtil.isAllow()) {
//                return;
//            }
            if (AwDataUtil.isEmpty(getText(binding.etCurrentNums))) {
                showMsg("请输入最少1位当前面板数值")
                return@setOnClickListener
            }
            showNumEnclosePopupWindow(
                mActivity,
                findViewById(R.id.iv_toEncloseSpecialNum),
                getText(binding.etCurrentNums)
            )
        }
        AwEditTextListener.isChangeListener(binding.etCurrentNums) { changed: Boolean ->
            if (changed) {
                handleAnalysisData()
                AppCacheUtil.setLastNums(getText(binding.etCurrentNums))
                writeFile("最后数据：" + AppCacheUtil.getLastNums())
            }
        }
        binding.ivBettingOptionalList.setOnClickListener { v: View? ->
            showNumPopupWindow(
                mActivity,
                binding.ivBettingOptionalList,
                object : NumPopupWindow.OnResultCallback{
                    override fun onResult(list: List<NumItemBean?>?, desc: String?) {
                        mBettingNumsList = list as MutableList<NumItemBean>?
                        val calResultBean = calResultCount(mBettingNumsList!!, -1)
                        setTextNoDefault(binding.tvMyNums, calResultBean.nums)
                    }

                })
        }
        binding.ivBettingOptionalImg.setOnClickListener { v: View? ->
            showNumImgPopupWindow(
                mActivity,
                binding.ivBettingOptionalImg,
                object : NumImgPopupWindow.OnResultCallback {
                    override fun onResult(list: List<NumItemBean?>?, desc: String?) {
                        mBettingNumsList = list as MutableList<NumItemBean>?
                        val calResultBean = calResultCount(mBettingNumsList!!, -1)
                        setTextNoDefault(binding.tvMyNums, calResultBean.nums)
                        setResultView(null)
                    }

                })
        }
        binding.ivBettingImitate.setOnClickListener { v: View? ->
            if (AppCacheUtil.getCalIntervalNum() == 1) {
                //单押7个数
                showNum7SingleCheckPopupWindow(
                    mActivity,
                    binding.ivBettingOptionalImg,
                    object : Num7SingleCheckPopupWindow.OnResultCallback {
                        override fun onResult(list: List<NumItemBean>?) {
                            mBettingNumsList = list as MutableList<NumItemBean>?
                            val calResultBean = calResultCount(mBettingNumsList!!, -1)
                            setTextNoDefault(binding.tvMyNums, calResultBean.nums)
                            setResultView(null)
                        }
                    })
            } else if (AppCacheUtil.getCalIntervalNum() == 2) {
                //单押5个数
                showNumSingleCheckPopupWindow(
                    mActivity,
                    binding.ivBettingOptionalImg,
                    object : NumSingleCheckPopupWindow.OnResultCallback {
                        override fun onResult(list: MutableList<NumItemBean>?) {
                            mBettingNumsList = list
                            val calResultBean = calResultCount(mBettingNumsList!!, -1)
                            setTextNoDefault(binding.tvMyNums, calResultBean.nums)
                            setResultView(null)
                        }

                    })
            } else if (AppCacheUtil.getCalIntervalNum() == 3) {
                //单押3个数
                showNum3SingleCheckPopupWindow(
                    mActivity,
                    binding.ivBettingOptionalImg,
                    object : Num3SingleCheckPopupWindow.OnResultCallback {
                        override fun onResult(list: List<NumItemBean?>?) {
                            mBettingNumsList = list as MutableList<NumItemBean>?
                            val calResultBean = calResultCount(mBettingNumsList!!, -1)
                            setTextNoDefault(binding.tvMyNums, calResultBean.nums)
                            setResultView(null)
                        }

                    })
            } else {
                showMsg("暂不支持的配置")
            }
        }
        findViewById<View>(R.id.iv_rateImitate).setOnClickListener { v: View? ->
//            if(!CommonUtil.isAllow()) {
//                return;
//            }
            showNumSingleCheckRateAnalysisPopupWindow(mActivity, findViewById(R.id.iv_rateImitate))
        }
        binding.ivBettingHandleInput.setOnClickListener { v: View? ->
            showNumHandleInputPopupWindow(
                mActivity,
                binding.ivBettingHandleInput,
                object : NumHandleInputPopupWindow.OnResultCallback {
                    override fun onResult(bean: NumHandleInputResultBean?) {
                        mBettingNumsList = bean?.list as MutableList<NumItemBean>?
                        val calResultBean = calResultCount(bean!!)
                        showResult(calResultBean)
                    }

                })
        }
        findViewById<View>(R.id.iv_delAllNums).setOnClickListener { v: View? ->
            showDialogWithCancelDismiss("确认清除当前面板数据么？") { v1: View? ->
                mDialog.dismiss()
                setTextNoDefault(binding.etCurrentNums, "")
                handleAnalysisData()
            }
        }
        findViewById<View>(R.id.iv_uiMoreSet).setOnClickListener { v: View? ->
            toClass(
                SettingUiActivity::class.java, false
            )
        }
    }

    private fun checkShowHelpCase() {
        //只有首次使用APP或者设置中默认启用功能帮助提示.
        if (AppCacheUtil.isFirstUseApp() || AppCacheUtil.isFunHelpHint()) {
            if (AppCacheUtil.isFirstUseApp()) {
                AppCacheUtil.setFirstUseApp(false)
            }
            showCase(
                mActivity,
                binding.ivBettingOptionalImg,
                "投注",
                "按照游戏内当轮下注内容投注\n(注: 点击弹框内部可关闭该提示)"
            ) { view: View? ->
                showCase(
                    mActivity,
                    binding.tvSelectResultNum,
                    "选取开奖数值",
                    "下注后，根据当轮游戏开奖结果选择对应数字\n选取数字后，会自动计算盈亏\n同时，将选取数字自动添加到面板数值最后一位，无需手动输入"
                ) { view1: View? ->
                    showCase(
                        mActivity,
                        binding.llResult,
                        "盈亏统计区",
                        "包含当轮及启动应用后的所有下注场次计算结果",
                        null
                    )
                }
            }
        }
    }

    override fun onResume() {
        super.onResume()

        showView(binding.rlHandleInputBetting, AppCacheUtil.isHandleInputBetting())
        showView(binding.llBettingCalArea, AppCacheUtil.isShowBettingCalArea())
        showView(binding.rgLimitLength, AppCacheUtil.isAnalysisQuick())
        showView(binding.ivBettingImitate, AppCacheUtil.isShowBettingImitate())
        if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_ALL) {
            binding.rBtnLimitAll.isChecked = true
        } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT1) {
            binding.rBtnLimit1.isChecked = true
        } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT2) {
            binding.rBtnLimit2.isChecked = true
        }
        setText(binding.rBtnLimit1, "后" + AppCacheUtil.getAnalysisLengthCustom() + "位")
        setText(binding.rBtnLimit2, "后" + AppCacheUtil.getLimitStatisticsCountCustom() + "位")
    }

    private fun showResult(bean: CalResultBean) {
        totalLooperCount++
        if (bean.isWin) {
            totalWinCount++
        }
        val winDes =
            "盈: " + totalWinCount + " ,亏: " + (totalLooperCount - totalWinCount) + " ,胜率: " + AwConvertUtil.getDivResult(
                totalWinCount.toDouble(),
                totalLooperCount.toDouble()
            ) + "%"
        setTextNoDefault(binding.tvRate, winDes)
        writeFile("****** END ******\n\n")
        writeFile("****** 第" + totalLooperCount + "轮 ******")
        writeFile("所有数字： " + getText(binding.etCurrentNums))
        if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_ALL) {
            writeFile("当轮分析方式： 所有")
        } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT1) {
            writeFile("当轮分析方式： " + "后" + AppCacheUtil.getAnalysisLengthCustom() + "位")
        } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT2) {
            writeFile("当轮分析方式： " + "后" + AppCacheUtil.getLimitStatisticsCountCustom() + "位")
        }
        writeFile("当轮分析数字： $mCalNums")
        writeFile("当轮分析： " + getText(binding.tvCaleCurrentResult) + " \n")
        writeFile(bean.nums)
        setTextNoDefault(binding.tvCaleCurrentResult, bean.nums)
        totalSilverCount += bean.resultSilver
        totalSkinCount += bean.resultSkin
        totalGemstoneCount += bean.resultGemstone
        val totalResult =
            "总计(盈亏净值): " + totalLooperCount + "轮 ,银 " + totalSilverCount + " ,皮 " + totalSkinCount + " ,宝石 " + totalGemstoneCount
        writeFile(totalResult)
        setTextNoDefault(binding.tvAllResultCount, totalResult)
        binding.etCurrentNums.append(bean.resultNumber.toString())
        mBettingNumsList = ArrayList()
        setTextNoDefault(binding.tvMyNums, "")
    }

    private fun handleAnalysisData() {
        customScreenOutPre = AppCacheUtil.getAnalysisNumsScreenOutPreCustom()
        if (AppCacheUtil.isTrendsAutoFilter()) {
            isHasCustomJumpSmooth = true
        } else {
            val list: List<CalSuggestItemBean> = allTrendList
            for (itemBean in list) {
                if (itemBean.isEnable) {
                    isHasCustomJumpSmooth = true
                }
            }
        }
        mCurrentNumOriginList = DataUtil.getCurrentNumsList(getText(binding.etCurrentNums)).toMutableList()
        if (getText(binding.etCurrentNums).length != 0) {
            setTextNoDefault(binding.tvAllNumsLeft, "面板区（" + getText(binding.etCurrentNums).length + "轮）")
        }
        mCalNums = getText(binding.etCurrentNums)
        val sb = StringBuffer()
        if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT1) {
            if (mCalNums.length > AppCacheUtil.getAnalysisLengthCustom()) {
                mCalNums =
                    mCalNums.substring(mCalNums.length - AppCacheUtil.getAnalysisLengthCustom())
            }
            sb.append("最后" + AppCacheUtil.getAnalysisLengthCustom() + "位：")
        } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT2) {
            if (mCalNums.length > AppCacheUtil.getLimitStatisticsCountCustom()) {
                mCalNums =
                    mCalNums.substring(mCalNums.length - AppCacheUtil.getLimitStatisticsCountCustom())
            }
            sb.append("最后" + AppCacheUtil.getLimitStatisticsCountCustom() + "位：")
        } else {
            sb.append("全部数字")
            if (AppCacheUtil.isNumsScreenOutPre() && getText(binding.etCurrentNums).length > customScreenOutPre) {
                sb.append("，筛除前" + customScreenOutPre + "位后：")
                //如果开启了前minLengthToScreenOut位过滤且总长度大于minLengthToScreenOut位, 以该过滤为准
                mCalNums = getText(binding.etCurrentNums).substring(
                    customScreenOutPre,
                    getText(binding.etCurrentNums).length
                )
            }
        }
        if (!sb.toString().contains("全部数字") || sb.toString().contains("筛除前")) {
            sb.append(mCalNums)
        }
        setTextNoDefault(binding.tvAnalysisNums, sb.toString())
        showCurrentResult()
    }

    /**
     * 处理分析结果
     */
    private fun showCurrentResult() {
        binding.tvCaleCurrentResult.text = ""
        if (AwDataUtil.isEmpty(getText(binding.etCurrentNums)) || getText(binding.etCurrentNums).length < 3) {
            binding.tvCaleCurrentResult.text = ""
            showView(binding.tvRecommendNums, false)
            showView(binding.rcvDataSuggestLeft, false)
            showView(binding.rcvDataSuggestRight, false)
            showView(binding.rcvDataAnalaysis, false)
            showView(binding.rcvDataAnalaysisCommon, false)
            showView(binding.rcvDataAnalaysisCombination, false)
            return
        }
        mCurrentNumList = DataUtil.getCurrentNumsList(mCalNums).toMutableList()
        val colorNumStr = getColorNumStr(mCurrentNumList)
        val bigAndSmallNumStr = getBigAndSmallNumStr(mCurrentNumList)
        val singularAndEvenNumStr = getSingularAndEvenNumStr(mCurrentNumList)
        val midEdgeNumStr = getMidEdgeNumStr(mCurrentNumList)
        mCalSuggestListLeft = ArrayList()
        mCalSuggestListRight = ArrayList()
        if (AppCacheUtil.isCommonAnalysis()) {
            if (AppCacheUtil.isAnalaysisModel2()) {
                showView(binding.rcvDataAnalaysisCommon, false)
                binding.tvCaleCurrentResult.text = "******** 走势（通用）********"
                appendCommon("\n")
                appendCommon(
                    matcherSearchText(
                        resources.getColor(R.color.black),
                        "颜色：",
                        "颜色：",
                        true
                    )
                )
                appendCommon(
                    matcherSearchText(
                        resources.getColor(com.aw.baselib.R.color.red),
                        colorNumStr,
                        "红",
                        true
                    )
                )
                appendCommon("\n")
                appendCommon(
                    matcherSearchText(
                        resources.getColor(R.color.black),
                        "大小：",
                        "大小：",
                        true
                    )
                )
                appendCommon(
                    matcherSearchText(
                        resources.getColor(com.aw.baselib.R.color.red),
                        bigAndSmallNumStr,
                        "小",
                        true
                    )
                )
                appendCommon("\n")
                appendCommon(
                    matcherSearchText(
                        resources.getColor(R.color.black),
                        "单双：",
                        "单双：",
                        true
                    )
                )
                appendCommon(
                    matcherSearchText(
                        resources.getColor(com.aw.baselib.R.color.red),
                        singularAndEvenNumStr,
                        "双",
                        true
                    )
                )
                appendCommon("\n")

//                appendCommon(matcherSearchText(getResources().getColor(R.color.black), "中偏：", "中偏：", true));
//                appendCommon(matcherSearchText(getResources().getColor(com.aw.baselib.R.color.red), midEdgeNumStr, "中", true));
//                appendCommon("\n");
                var statisticsCountList = mCurrentNumList
                if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT1) {
                    if (mCurrentNumList.size > AppCacheUtil.getAnalysisLengthCustom()) {
                        //开启了限制统计数量长度， 并且当前已有数值长度大于自定义设置的数量
                        statisticsCountList = statisticsCountList.subList(
                            statisticsCountList.size - AppCacheUtil.getAnalysisLengthCustom(),
                            statisticsCountList.size
                        )
                    }
                } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT2) {
                    if (mCurrentNumList.size > AppCacheUtil.getLimitStatisticsCountCustom()) {
                        //开启了限制统计数量长度， 并且当前已有数值长度大于自定义设置的数量
                        statisticsCountList = statisticsCountList.subList(
                            statisticsCountList.size - AppCacheUtil.getLimitStatisticsCountCustom(),
                            statisticsCountList.size
                        )
                    }
                }
                appendStatistics(
                    matcherSearchText(
                        getBetterColor(
                            mActivity,
                            getBigNumCount(statisticsCountList),
                            getSmallNumCount(statisticsCountList)
                        ), "大数：", "大数：", judgeGreater(
                            getBigNumCount(statisticsCountList),
                            getSmallNumCount(statisticsCountList)
                        )
                    )
                )
                appendStatistics(
                    getBigNumCount(statisticsCountList).size.toString() + "个（" + getDesignatedNums(
                        getBigNumCount(statisticsCountList)
                    ) + "）"
                )
                appendStatistics("\n")
                appendStatistics(
                    matcherSearchText(
                        getBetterColor(
                            mActivity,
                            getSmallNumCount(statisticsCountList),
                            getBigNumCount(statisticsCountList)
                        ), "小数：", "小数：", judgeGreater(
                            getSmallNumCount(statisticsCountList),
                            getBigNumCount(statisticsCountList)
                        )
                    )
                )
                appendStatistics(
                    getSmallNumCount(statisticsCountList).size.toString() + "个（" + getDesignatedNums(
                        getSmallNumCount(statisticsCountList)
                    ) + "）"
                )
                appendStatistics("\n")
                appendStatistics(
                    matcherSearchText(
                        getBetterColor(
                            mActivity,
                            getSingularNumCount(statisticsCountList),
                            getEvenNumCount(statisticsCountList)
                        ), "单数：", "单数：", judgeGreater(
                            getSingularNumCount(statisticsCountList),
                            getEvenNumCount(statisticsCountList)
                        )
                    )
                )
                appendStatistics(
                    getSingularNumCount(statisticsCountList).size.toString() + "个（" + getDesignatedNums(
                        getSingularNumCount(statisticsCountList)
                    ) + "）"
                )
                appendStatistics("\n")
                appendStatistics(
                    matcherSearchText(
                        getBetterColor(
                            mActivity,
                            getEvenNumCount(statisticsCountList),
                            getSingularNumCount(statisticsCountList)
                        ), "双数：", "双数：", judgeGreater(
                            getEvenNumCount(statisticsCountList),
                            getSingularNumCount(statisticsCountList)
                        )
                    )
                )
                appendStatistics(
                    getEvenNumCount(statisticsCountList).size.toString() + "个（" + getDesignatedNums(
                        getEvenNumCount(statisticsCountList)
                    ) + "）"
                )
                appendStatistics("\n")
                appendStatistics(
                    matcherSearchText(
                        getBetterColor(
                            mActivity,
                            getNumList_red(statisticsCountList),
                            getNumList_yellows(statisticsCountList)
                        ), "红数：", "红数：", judgeGreater(
                            getNumList_red(statisticsCountList),
                            getNumList_yellows(statisticsCountList)
                        )
                    )
                )
                appendStatistics(
                    getNumList_red(statisticsCountList).size.toString() + "个（" + getDesignatedNums(
                        getNumList_red(statisticsCountList)
                    ) + "）"
                )
                appendStatistics("\n")
                appendStatistics(
                    matcherSearchText(
                        getBetterColor(
                            mActivity,
                            getNumList_yellows(statisticsCountList),
                            getNumList_red(statisticsCountList)
                        ), "黄数：", "黄数：", judgeGreater(
                            getNumList_yellows(statisticsCountList),
                            getNumList_red(statisticsCountList)
                        )
                    )
                )
                appendStatistics(
                    getNumList_yellows(statisticsCountList).size.toString() + "个（" + getDesignatedNums(
                        getNumList_yellows(statisticsCountList)
                    ) + "）"
                )
                appendStatistics("\n")
                appendCommon(
                    matcherSearchText(
                        resources.getColor(R.color.black),
                        "面板：",
                        "面板：",
                        false
                    )
                )
                appendCommon(getDashboardNumStr(getText(binding.etCurrentNums)))
                if (AppCacheUtil.isColdAndHotDefault()) {
                    appendCommon("\n面板\n")
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(R.color.black),
                            "冷号：",
                            "冷号：",
                            false
                        )
                    )
                    appendCommon(
                        getColdNumList(mCurrentNumOriginList).size.toString() + "个（" + getDesignatedNums(
                            getColdNumList(mCurrentNumOriginList)
                        ) + "）"
                    )
                    appendCommon("\n")
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(R.color.black),
                            "热号：",
                            "热号：",
                            false
                        )
                    )
                    if (AppCacheUtil.isHotShowModelDetail()) {
                        appendCommon(getHotNumStr(mCurrentNumOriginList)[0])
                    } else {
                        appendCommon(getHotNumStr(mCurrentNumOriginList)[2])
                    }
                    appendCommon("，")
                    val maxHotNumStr = getHotNumStr(mCurrentNumOriginList)[1]
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(com.aw.baselib.R.color.red),
                            maxHotNumStr,
                            "最热号",
                            false
                        )
                    )
                }
                if (AppCacheUtil.isColdAndHotCustom()) {
                    appendCommon("\n区域\n")
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(R.color.black),
                            "冷号：",
                            "冷号：",
                            false
                        )
                    )
                    appendCommon(
                        getColdNumList(mCurrentNumList).size.toString() + "个（" + getDesignatedNums(
                            getColdNumList(mCurrentNumList)
                        ) + "）"
                    )
                    appendCommon("\n")
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(R.color.black),
                            "热号：",
                            "热号：",
                            false
                        )
                    )
                    if (AppCacheUtil.isHotShowModelDetail()) {
                        appendCommon(getHotNumStr(mCurrentNumList)[0])
                    } else {
                        appendCommon(getHotNumStr(mCurrentNumList)[2])
                    }
                    appendCommon("，")
                    val maxHotNumStr = getHotNumStr(mCurrentNumList)[1]
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(com.aw.baselib.R.color.red),
                            maxHotNumStr,
                            "最热号",
                            false
                        )
                    )
                }

                //                appendCommon(matcherSearchText(getResources().getColor(R.color.black), "组合：", "组合："));
                //                String matchBlockResultStr = "02358: " + (isMatchBlock(NumEnums.BLOCK_02358.code, mCurrentNumList) ? "是" : "否") + ",  12479: " + (isMatchBlock(NumEnums.BLOCK_12479.code, mCurrentNumList) ? "是" : "否")
                //                        + ",  369: " + (isMatchBlock(NumEnums.BLOCK_369.code, mCurrentNumList) ? "是" : "否") + ",  01689: " + (isMatchBlock(NumEnums.BLOCK_01689.code, mCurrentNumList) ? "是" : "否");
                //                appendCommon(matcherSearchText(getResources().getColor(com.aw.baselib.R.color.red), matchBlockResultStr, "是"));
                //                appendCommon("\n");
                if (AppCacheUtil.isStatisticsCountMax()) {
                    appendCommon("\n")
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(com.aw.baselib.R.color.red),
                            "Max：",
                            "Max：",
                            true
                        )
                    )
                    //                    String everyMaxCount = getEveryMaxCountStr(colorNumStr, bigAndSmallNumStr, singularAndEvenNumStr);
                    //                    appendCommon(everyMaxCount);
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(com.aw.baselib.R.color.red),
                            getSingleMaxCountStr(colorNumStr, "红"),
                            "红",
                            true
                        )
                    )
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(com.aw.baselib.R.color.red),
                            getSingleMaxCountStr(colorNumStr, "黄"),
                            "黄",
                            true
                        )
                    )
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(com.aw.baselib.R.color.red),
                            getSingleMaxCountStr(bigAndSmallNumStr, "大"),
                            "大",
                            true
                        )
                    )
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(com.aw.baselib.R.color.red),
                            getSingleMaxCountStr(bigAndSmallNumStr, "小"),
                            "小",
                            true
                        )
                    )
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(com.aw.baselib.R.color.red),
                            getSingleMaxCountStr(singularAndEvenNumStr, "单"),
                            "单",
                            true
                        )
                    )
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(com.aw.baselib.R.color.red),
                            getSingleMaxCountStr(singularAndEvenNumStr, "双"),
                            "双",
                            true
                        )
                    )
                }

                //通用建议数字
                if (AppCacheUtil.isCommonSuggest()) {
                    mCalSuggestListLeft.add(
                        CalSuggestItemBean(
                            TrendTagEnums.TREND0_1_1.code,
                            TrendTagEnums.TREND0_1_1.type,
                            "单",
                            getDesignatedNums(getSingularNumCount(statisticsCountList)),
                            getBetterTrends("单", statisticsCountList)
                        )
                    )
                    mCalSuggestListRight.add(
                        CalSuggestItemBean(
                            TrendTagEnums.TREND0_1_2.code,
                            TrendTagEnums.TREND0_1_2.type,
                            "双",
                            getDesignatedNums(getEvenNumCount(statisticsCountList)),
                            getBetterTrends("双", statisticsCountList)
                        )
                    )
                    mCalSuggestListLeft.add(
                        CalSuggestItemBean(
                            TrendTagEnums.TREND0_2_1.code,
                            TrendTagEnums.TREND0_2_1.type,
                            "大",
                            getDesignatedNums(getBigNumCount(statisticsCountList)),
                            getBetterTrends("大", statisticsCountList)
                        )
                    )
                    mCalSuggestListRight.add(
                        CalSuggestItemBean(
                            TrendTagEnums.TREND0_2_2.code,
                            TrendTagEnums.TREND0_2_2.type,
                            "小",
                            getDesignatedNums(getSmallNumCount(statisticsCountList)),
                            getBetterTrends("小", statisticsCountList)
                        )
                    )
                    mCalSuggestListLeft.add(
                        CalSuggestItemBean(
                            TrendTagEnums.TREND0_3_1.code,
                            TrendTagEnums.TREND0_3_1.type,
                            "红",
                            getDesignatedNums(getNumList_red(statisticsCountList)),
                            getBetterTrends("红", statisticsCountList)
                        )
                    )
                    mCalSuggestListRight.add(
                        CalSuggestItemBean(
                            TrendTagEnums.TREND0_3_2.code,
                            TrendTagEnums.TREND0_3_2.type,
                            "黄",
                            getDesignatedNums(getNumList_yellows(statisticsCountList)),
                            getBetterTrends("黄", statisticsCountList)
                        )
                    )
                }
            } else {
                appendCommon(
                    matcherSearchText(
                        resources.getColor(R.color.black),
                        "面板：",
                        "面板：",
                        false
                    )
                )
                appendCommon(getDashboardNumStr(getText(binding.etCurrentNums)))
                if (AppCacheUtil.isColdAndHotDefault()) {
                    appendCommon("\n面板\n")
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(R.color.black),
                            "冷号：",
                            "冷号：",
                            false
                        )
                    )
                    appendCommon(
                        getColdNumList(mCurrentNumOriginList).size.toString() + "个（" + getDesignatedNums(
                            getColdNumList(mCurrentNumOriginList)
                        ) + "）"
                    )
                    appendCommon("\n")
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(R.color.black),
                            "热号：",
                            "热号：",
                            false
                        )
                    )
                    if (AppCacheUtil.isHotShowModelDetail()) {
                        appendCommon(getHotNumStr(mCurrentNumOriginList)[0])
                    } else {
                        appendCommon(getHotNumStr(mCurrentNumOriginList)[2])
                    }
                    appendCommon("，")
                    val maxHotNumStr = getHotNumStr(mCurrentNumOriginList)[1]
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(com.aw.baselib.R.color.red),
                            maxHotNumStr,
                            "最热号",
                            false
                        )
                    )
                }
                if (AppCacheUtil.isColdAndHotCustom()) {
                    appendCommon("\n区域\n")
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(R.color.black),
                            "冷号：",
                            "冷号：",
                            false
                        )
                    )
                    appendCommon(
                        getColdNumList(mCurrentNumList).size.toString() + "个（" + getDesignatedNums(
                            getColdNumList(mCurrentNumList)
                        ) + "）"
                    )
                    appendCommon("\n")
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(R.color.black),
                            "热号：",
                            "热号：",
                            false
                        )
                    )
                    if (AppCacheUtil.isHotShowModelDetail()) {
                        appendCommon(getHotNumStr(mCurrentNumList)[0])
                    } else {
                        appendCommon(getHotNumStr(mCurrentNumList)[2])
                    }
                    appendCommon("，")
                    val maxHotNumStr = getHotNumStr(mCurrentNumList)[1]
                    appendCommon(
                        matcherSearchText(
                            resources.getColor(com.aw.baselib.R.color.red),
                            maxHotNumStr,
                            "最热号",
                            false
                        )
                    )
                }
                showView(binding.rcvDataAnalaysisCommon, true)
                mAllCalAnalaysisCommonList = ArrayList()
                appendCommonTrendsToRecyclerView(
                    getAnalysisResultList(
                        TrendTagEnums.TREND_COMMON.type,
                        mCurrentNumOriginList
                    ), getTrendEnumsList(TrendTagEnums.TREND_COMMON.type)
                )
                mainCalAnalaysisAdapterCommon!!.addAllData(mAllCalAnalaysisCommonList)
            }
            if (isHasCustomJumpSmooth) {
                appendCommon("\n")
            }
        }
        if (AppCacheUtil.isCombinationAnalysis()) {
            //添加组合分析
            mAllCalAnalaysisCombinationList = ArrayList()
            appendCombinationTrendsToRecyclerView(combinationEnumsList)
            mCombinationAdapter!!.addAllData(mAllCalAnalaysisCombinationList)
            showView(binding.rcvDataAnalaysisCombination, true)
        } else {
            showView(binding.rcvDataAnalaysisCombination, false)
        }
        if (isHasCustomJumpSmooth) {
            showView(binding.tvRecommendNums, true)
            if (AppCacheUtil.isAnalaysisModel2()) {
                showView(binding.rcvDataAnalaysis, false)
                appendTrends(
                    getAnalysisResultList(TrendTagEnums.TREND1_1_1.type, mCurrentNumList as MutableList<Int>),
                    getTrendEnumsList(TrendTagEnums.TREND1_1_1.type)
                )
                appendCommon("\n")
                appendTrends(
                    getAnalysisResultList(TrendTagEnums.TREND2_1_1.type, mCurrentNumList as MutableList<Int>),
                    getTrendEnumsList(TrendTagEnums.TREND2_1_1.type)
                )
                appendCommon("\n")
                appendTrends(
                    getAnalysisResultList(TrendTagEnums.TREND3_1_1.type, mCurrentNumList as MutableList<Int>),
                    getTrendEnumsList(TrendTagEnums.TREND3_1_1.type)
                )
            } else {
                showView(binding.rcvDataAnalaysis, true)
                mAllCalAnalaysisList = ArrayList()
                appendTrendsToRecyclerView(
                    getAnalysisResultList(
                        TrendTagEnums.TREND1_1_1.type,
                        mCurrentNumOriginList as MutableList<Int>
                    ), getTrendEnumsList(TrendTagEnums.TREND1_1_1.type)
                )
                appendTrendsToRecyclerView(
                    getAnalysisResultList(
                        TrendTagEnums.TREND2_1_1.type,
                        mCurrentNumOriginList as MutableList<Int>
                    ), getTrendEnumsList(TrendTagEnums.TREND2_1_1.type)
                )
                appendTrendsToRecyclerView(
                    getAnalysisResultList(
                        TrendTagEnums.TREND3_1_1.type,
                        mCurrentNumOriginList as MutableList<Int>
                    ), getTrendEnumsList(TrendTagEnums.TREND3_1_1.type)
                )
                mainCalAnalaysisAdapter!!.addAllData(mAllCalAnalaysisList)
                isHasCustomJumpSmooth = !AwDataUtil.isEmpty(mAllCalAnalaysisList)
                if (!isHasCustomJumpSmooth) {
                    if (AppCacheUtil.isTrendsAutoFilter()) {
                        appendCommon("\n")
                        appendCommon(
                            matcherSearchText(
                                resources.getColor(com.aw.baselib.R.color.red),
                                "*** 自动过滤已开启，本轮暂无自定义走势匹配项 ***",
                                "自动过滤已开启，本轮暂无自定义走势匹配项",
                                true
                            )
                        )
                        appendCommon("\n")
                    } else {
                        appendCommon("\n")
                        appendCommon(
                            matcherSearchText(
                                resources.getColor(com.aw.baselib.R.color.red),
                                "*** 自动过滤已关闭，本轮暂无自定义走势匹配项 ***",
                                "自动过滤已关闭，本轮暂无自定义走势匹配项",
                                true
                            )
                        )
                        appendCommon("\n")
                    }
                }
            }
            mCalSuggestAdapterLeft!!.addAllData(mCalSuggestListLeft)
            mCalSuggestAdapterRight!!.addAllData(mCalSuggestListRight)
        }

        //|| AppCacheUtil.isCommonSuggest()
        if (isHasCustomJumpSmooth) {
            showView(binding.tvRecommendNums, true)
            showView(binding.rcvDataSuggestLeft, true)
            showView(binding.rcvDataSuggestRight, true)
        } else {
            showView(binding.tvRecommendNums, false)
            showView(binding.rcvDataSuggestLeft, false)
            showView(binding.rcvDataSuggestRight, false)
        }
    }

    private fun appendEveryTrend(txt: SpannableString, isCount: Boolean) {
        if (!AppCacheUtil.isStatisticsCount() && isCount) {
            return
        }
        binding.tvCaleCurrentResult.append(txt)
    }

    private fun appendEveryTrend(txt: String, isCount: Boolean) {
        if (!AppCacheUtil.isStatisticsCount() && isCount) {
            return
        }
        binding.tvCaleCurrentResult.append(txt)
    }

    /**
     * 添加分析通用内容
     *
     * @param txt
     */
    private fun appendCommon(txt: Any) {
        if (txt is String) {
            appendEveryTrend(txt, false)
        } else if (txt is SpannableString) {
            appendEveryTrend(txt, false)
        }
    }

    /**
     * 添加个数统计内容
     *
     * @param txt
     */
    private fun appendStatistics(txt: Any) {
        if (txt is String) {
            appendEveryTrend(txt, true)
        } else if (txt is SpannableString) {
            appendEveryTrend(txt, true)
        }
    }

    /**
     * 封装自定义走势展示
     *
     * @param resultBeanList    每种走势对象集合（顺顺顺跳跳顺。。。。。）
     * @param trendTagEnumsList 每种走势枚举集合（长度与resultBeanList相同）
     */
    private fun appendTrends(
        resultBeanList: List<AnalysisDataResultBean?>,
        trendTagEnumsList: List<TrendTagEnums>
    ) {
        var isExist = false
        AwLog.d("appendTrends type: " + trendTagEnumsList[0].type)
        val strList: MutableList<String?> = ArrayList()
        val indexList: MutableList<Int> = ArrayList()
        for (i in resultBeanList.indices) {
            val itemBean = resultBeanList[i]
            AwLog.d("appendTrends itemBean: " + itemBean.toString())
            val calResult = if (itemBean == null) "" else itemBean.calResultStr
            val mSortNumList = if (calResult == null) ArrayList() else itemBean!!.sortNumsList!!
            if (AppCacheUtil.isTrendActive(trendTagEnumsList[i].code)) {
                //判断是否智能显示开启，根据匹配项展示
                val calSuggestItemBeanLeft = CalSuggestItemBean(
                    trendTagEnumsList[i].code, trendTagEnumsList[i].type, "顺" + (i + 1),
                    getDesignatedNums(mSortNumList as MutableList<Int>), getBetterTrends(false, calResult!!)
                )
                calSuggestItemBeanLeft.strValue = calResult
                val calSuggestItemBeanRight = CalSuggestItemBean(
                    trendTagEnumsList[i].code,
                    trendTagEnumsList[i].type,
                    "跳" + (i + 1),
                    getDesignatedNums(getJumpNumList(mSortNumList)),
                    getBetterTrends(true, calResult)
                )
                if (!AppCacheUtil.isTrendsAutoFilter()) {
                    isExist = true
                    strList.add(calResult)
                    mCalSuggestListLeft.add(calSuggestItemBeanLeft)
                    mCalSuggestListRight.add(calSuggestItemBeanRight)
                } else if (calSuggestItemBeanLeft.isSuggestItem || calSuggestItemBeanRight.isSuggestItem) {
                    isExist = true
                    indexList.add(i)
                    strList.add(calResult)
                    mCalSuggestListLeft.add(calSuggestItemBeanLeft)
                    mCalSuggestListRight.add(calSuggestItemBeanRight)
                }
            } else {
                strList.add("")
            }
        }
        appendCommon("******** " + trendTagEnumsList[0].type + "********")
        appendCommon("\n")
        if (isExist) {
            appendEveryTrend(strList, indexList)
        } else {
            if (AppCacheUtil.isTrendsAutoFilter()) {
                appendCommon(
                    matcherSearchText(
                        resources.getColor(com.aw.baselib.R.color.red),
                        "自动过滤已开启，本轮暂无匹配项",
                        "自动过滤已开启",
                        true
                    )
                )
            } else {
                appendCommon(
                    matcherSearchText(
                        resources.getColor(com.aw.baselib.R.color.red),
                        "自动过滤已关闭，本轮无匹配项",
                        "",
                        true
                    )
                )
            }
        }
    }

    /**
     * 封装自定义走势展示
     *
     * @param resultBeanList    每种走势对象集合（顺顺顺跳跳顺。。。。。）
     * @param trendTagEnumsList 每种走势枚举集合（长度与resultBeanList相同）
     */
    private fun appendTrendsToRecyclerView(
        resultBeanList: List<AnalysisDataResultBean?>,
        trendTagEnumsList: List<TrendTagEnums>
    ) {
        AwLog.d("appendTrends type: " + trendTagEnumsList[0].type)
        for (i in resultBeanList.indices) {
            val itemBean = resultBeanList[i]
            if (itemBean != null) {
                AwLog.d("appendTrends itemBean: $itemBean")
            }
            val calResult = if (itemBean == null) "" else itemBean.calResultStr
            var pre15Str = ""
            var screenOutPreStr = ""
            var lastLimitStr = ""
            var lastStatisicsStr = ""
            pre15Str = if (calResult!!.length > 15) {
                calResult.substring(0, 15)
            } else {
                calResult
            }
            screenOutPreStr =
                if (calResult.length > AppCacheUtil.getAnalysisNumsScreenOutPreCustom()) {
                    calResult.substring(AppCacheUtil.getAnalysisNumsScreenOutPreCustom())
                } else {
                    ""
                }
            lastLimitStr = if (calResult.length > AppCacheUtil.getAnalysisLengthCustom()) {
                calResult.substring(calResult.length - AppCacheUtil.getAnalysisLengthCustom())
            } else {
                calResult
            }
            lastStatisicsStr =
                if (calResult.length > AppCacheUtil.getLimitStatisticsCountCustom()) {
                    calResult.substring(calResult.length - AppCacheUtil.getLimitStatisticsCountCustom())
                } else {
                    calResult
                }
            val mSortNumList =
                if (calResult == null) ArrayList() else (if (itemBean == null) ArrayList() else itemBean.sortNumsList)
            AwLog.d(
                "appendTrendsToRecyclerView code: " + trendTagEnumsList[i].code + " ,isTrendActive: " + AppCacheUtil.isTrendActive(
                    trendTagEnumsList[i].code
                )
            )
            if (AppCacheUtil.isTrendActive(trendTagEnumsList[i].code)) {
                val typeNameJump = "跳"
                val typeNameSort = "顺"
                //判断是否智能显示开启，根据匹配项展示
                var calSuggestItemBeanLeft: CalSuggestItemBean? = null
                calSuggestItemBeanLeft = if (AppCacheUtil.isUseBetterTrendsPercent()) {
                    //判断是否启用择优比重
                    CalSuggestItemBean(
                        trendTagEnumsList[i].code, trendTagEnumsList[i].type, "顺" + (i + 1),
                        mSortNumList?.let { getDesignatedNums(it as MutableList<Int>) }, getBetterTrends(false, calResult)
                    )
                } else {
                    CalSuggestItemBean(
                        trendTagEnumsList[i].code,
                        trendTagEnumsList[i].type,
                        "顺" + (i + 1),
                        mSortNumList?.let { getDesignatedNums(it as MutableList<Int>) },
                        getBetterTrends(false, calResult) || judgeJumpSmoothlyMaxCountEndStr(
                            calResult, "顺"
                        )
                    )
                }
                calSuggestItemBeanLeft.strValue = calResult
                var calSuggestItemBeanRight: CalSuggestItemBean? = null
                calSuggestItemBeanRight = if (AppCacheUtil.isUseBetterTrendsPercent()) {
                    CalSuggestItemBean(
                        trendTagEnumsList[i].code,
                        trendTagEnumsList[i].type,
                        "跳" + (i + 1),
                        getDesignatedNums(getJumpNumList(mSortNumList as MutableList<Int>)),
                        getBetterTrends(true, calResult)
                    )
                } else {
                    CalSuggestItemBean(
                        trendTagEnumsList[i].code,
                        trendTagEnumsList[i].type,
                        "跳" + (i + 1),
                        getDesignatedNums(getJumpNumList(mSortNumList as MutableList<Int>)),
                        getBetterTrends(true, calResult) || judgeJumpSmoothlyMaxCountEndStr(
                            calResult, "跳"
                        )
                    )
                }
                var calAnalaysisItemBean: CalSuggestItemBean? = null
                calAnalaysisItemBean = if (AppCacheUtil.isUseBetterTrendsPercent()) {
                    CalSuggestItemBean(
                        trendTagEnumsList[i].code,
                        trendTagEnumsList[i].type,
                        "走势" + (i + 1),
                        getDesignatedNums(getJumpNumList(mSortNumList)),
                        getBetterTrends(true, calResult)
                    )
                } else {
                    CalSuggestItemBean(
                        trendTagEnumsList[i].code,
                        trendTagEnumsList[i].type,
                        "走势" + (i + 1),
                        getDesignatedNums(getJumpNumList(mSortNumList)),
                        getBetterTrends(true, calResult) || judgeJumpSmoothlyMaxCountEndStr(
                            calResult, ""
                        )
                    )
                }
                //计算所有数值的次数
                calAnalaysisItemBean.countAllTypeJump = countOccurrences(
                    calResult,
                    typeNameJump
                )
                calAnalaysisItemBean.countAllTypeSort = countOccurrences(
                    calResult,
                    typeNameSort
                )
                //计算前15位数值的次数
                calAnalaysisItemBean.countPre15Type1 = countOccurrences(pre15Str, typeNameJump)
                calAnalaysisItemBean.countPre15Type2 = countOccurrences(pre15Str, typeNameSort)
                if (AppCacheUtil.isNumsScreenOutPre()) {
                    //TODO 为了统计显示, 不做控制
                }
                //计算过滤后前minLengthToScreenOut位后所有数值的次数
                calAnalaysisItemBean.countPreTypeJump =
                    countOccurrences(screenOutPreStr, typeNameJump)
                calAnalaysisItemBean.countPreTypeSort =
                    countOccurrences(screenOutPreStr, typeNameSort)

                //计算限制自定义分析长度的所有数值的次数
                calAnalaysisItemBean.limitCountAllTypeJump =
                    countOccurrences(lastLimitStr, typeNameJump)
                calAnalaysisItemBean.limitCountAllTypeSort =
                    countOccurrences(lastLimitStr, typeNameSort)

                //计算限制数量统计的所有数值的次数
                calAnalaysisItemBean.limitCountTypeJump =
                    countOccurrences(lastStatisicsStr, typeNameJump)
                calAnalaysisItemBean.limitCountTypeSort =
                    countOccurrences(lastStatisicsStr, typeNameSort)
                if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_ALL) {
                    calAnalaysisItemBean.strValue = calResult
                } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT1) {
                    calAnalaysisItemBean.strValue = lastLimitStr
                } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT2) {
                    calAnalaysisItemBean.strValue = lastStatisicsStr
                }
                calAnalaysisItemBean.typeNameJump = typeNameJump
                calAnalaysisItemBean.typeNameSort = typeNameSort
                if (!AppCacheUtil.isTrendsAutoFilter() || calSuggestItemBeanLeft.isSuggestItem || calSuggestItemBeanRight.isSuggestItem) {
                    mAllCalAnalaysisList.add(calAnalaysisItemBean)
                    mCalSuggestListLeft.add(calSuggestItemBeanLeft)
                    mCalSuggestListRight.add(calSuggestItemBeanRight)
                }
            }
        }
    }

    /**
     * 封装通用走势展示
     *
     * @param resultBeanList    每种走势对象集合（红黄。。。。。  单双.....  大小....）
     * @param trendTagEnumsList 每种走势枚举集合（长度与resultBeanList相同）
     */
    private fun appendCommonTrendsToRecyclerView(
        resultBeanList: List<AnalysisDataResultBean?>,
        trendTagEnumsList: List<TrendTagEnums>
    ) {
        AwLog.d("appendTrends type: " + trendTagEnumsList[0].type)
        for (i in resultBeanList.indices) {
            val itemBean = resultBeanList[i]
            AwLog.d("appendTrends itemBean: " + itemBean.toString())
            val calResult = if (itemBean == null) "" else itemBean.calResultStr!!
            var pre15Str = ""
            var screenOutPreStr = ""
            var lastLimitStr = ""
            var lastStatisicsStr = ""
            pre15Str = if (calResult.length > 15) {
                calResult.substring(0, 15)
            } else {
                calResult
            }
            screenOutPreStr =
                if (calResult.length > AppCacheUtil.getAnalysisNumsScreenOutPreCustom()) {
                    calResult.substring(AppCacheUtil.getAnalysisNumsScreenOutPreCustom())
                } else {
                    ""
                }
            lastLimitStr = if (calResult.length > AppCacheUtil.getAnalysisLengthCustom()) {
                calResult.substring(calResult.length - AppCacheUtil.getAnalysisLengthCustom())
            } else {
                calResult
            }
            lastStatisicsStr =
                if (calResult.length > AppCacheUtil.getLimitStatisticsCountCustom()) {
                    calResult.substring(calResult.length - AppCacheUtil.getLimitStatisticsCountCustom())
                } else {
                    calResult
                }
            //判断是否展示通用分析
            if (AppCacheUtil.isCommonAnalysis()) {
                var typeName1 = ""
                var typeName2 = ""
                val calAnalaysisItemBean = CalSuggestItemBean(
                    trendTagEnumsList[i].code,
                    trendTagEnumsList[i].type,
                    trendTagEnumsList[i].desc
                )
                if (trendTagEnumsList[i].code == TrendTagEnums.TREND0_1_1.code) {
                    //单双
                    typeName1 = "单"
                    typeName2 = "双"
                } else if (trendTagEnumsList[i].code == TrendTagEnums.TREND0_2_1.code) {
                    //大小
                    typeName1 = "大"
                    typeName2 = "小"
                } else if (trendTagEnumsList[i].code == TrendTagEnums.TREND0_3_1.code) {
                    //颜色
                    typeName1 = "红"
                    typeName2 = "黄"
                } else if (trendTagEnumsList[i].code == TrendTagEnums.TREND0_4_1.code) {
                    //颜色
                    typeName1 = "中"
                    typeName2 = "偏"
                }
                //计算所有数值的次数
                calAnalaysisItemBean.countAllTypeJump = countOccurrences(calResult, typeName1)
                calAnalaysisItemBean.countAllTypeSort = countOccurrences(calResult, typeName2)
                //计算前15位数值的次数
                calAnalaysisItemBean.countPre15Type1 = countOccurrences(pre15Str, typeName1)
                calAnalaysisItemBean.countPre15Type2 = countOccurrences(pre15Str, typeName2)
                if (AppCacheUtil.isNumsScreenOutPre()) {
                    //TODO 为了统计显示, 不做控制
                }
                //计算过滤后前customScreenOutPre位后所有数值的次数
                calAnalaysisItemBean.countPreTypeJump = countOccurrences(screenOutPreStr, typeName1)
                calAnalaysisItemBean.countPreTypeSort = countOccurrences(screenOutPreStr, typeName2)

                //计算限制自定义分析长度的所有数值的次数
                calAnalaysisItemBean.limitCountAllTypeJump =
                    countOccurrences(lastLimitStr, typeName1)
                calAnalaysisItemBean.limitCountAllTypeSort =
                    countOccurrences(lastLimitStr, typeName2)

                //计算限制数量统计的所有数值的次数
                calAnalaysisItemBean.limitCountTypeJump =
                    countOccurrences(lastStatisicsStr, typeName1)
                calAnalaysisItemBean.limitCountTypeSort =
                    countOccurrences(lastStatisicsStr, typeName2)
                if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_ALL) {
                    calAnalaysisItemBean.strValue = calResult
                } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT1) {
                    calAnalaysisItemBean.strValue = lastLimitStr
                } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT2) {
                    calAnalaysisItemBean.strValue = lastStatisicsStr
                }
                calAnalaysisItemBean.typeNameJump = typeName1
                calAnalaysisItemBean.typeNameSort = typeName2
                mAllCalAnalaysisCommonList.add(calAnalaysisItemBean)
            }
        }
    }

    /**
     * 封装组合走势展示
     *
     * @param combinationTagEnumsList 每种组合枚举集合（
     */
    private fun appendCombinationTrendsToRecyclerView(combinationTagEnumsList: List<CombinationTagEnums>) {
        AwLog.d("appendCombinationTrendsToRecyclerView type: " + combinationTagEnumsList[0].type)
        for (i in combinationTagEnumsList.indices) {
            val tagEnums = combinationTagEnumsList[i]
            AwLog.d("appendCombinationTrendsToRecyclerView tagEnums: $tagEnums")
            val allStr = convertListToStr(mCurrentNumOriginList)
            var pre15Str = ""
            var screenOutPreStr = ""
            var limitStr1 = ""
            var limitStr2 = ""
            pre15Str = if (mCurrentNumOriginList.size > 15) {
                convertListToStr(mCurrentNumOriginList.subList(0, 15))
            } else {
                convertListToStr(mCurrentNumOriginList)
            }
            screenOutPreStr =
                if (allStr.length > AppCacheUtil.getAnalysisNumsScreenOutPreCustom()) {
                    convertListToStr(
                        mCurrentNumOriginList.subList(
                            AppCacheUtil.getAnalysisNumsScreenOutPreCustom(),
                            mCurrentNumOriginList.size
                        )
                    )
                } else {
                    ""
                }
            limitStr1 = if (allStr.length > AppCacheUtil.getAnalysisLengthCustom()) {
                convertListToStr(
                    mCurrentNumOriginList.subList(
                        allStr.length - AppCacheUtil.getAnalysisLengthCustom(),
                        mCurrentNumOriginList.size
                    )
                )
            } else {
                allStr
            }
            limitStr2 = if (allStr.length > AppCacheUtil.getLimitStatisticsCountCustom()) {
                convertListToStr(
                    mCurrentNumOriginList.subList(
                        allStr.length - AppCacheUtil.getLimitStatisticsCountCustom(),
                        mCurrentNumOriginList.size
                    )
                )
            } else {
                allStr
            }
            //判断是否展示组合分析
            if (AppCacheUtil.isCombinationAnalysis()) {
                val combinationItemBean = AnalysisCombinationItemBean()
                combinationItemBean.type = tagEnums.type
                combinationItemBean.name = tagEnums.desc
                combinationItemBean.totalCount = allStr.length
                combinationItemBean.totalCountPre15 = pre15Str.length
                combinationItemBean.totalCountOutPre15 = screenOutPreStr.length
                combinationItemBean.totalCountLimit1 = limitStr1.length
                combinationItemBean.totalCountLimit2 = limitStr2.length
                //计算所有数值 组合内数字的次数
                combinationItemBean.countAll = getCombinationCount(allStr, tagEnums.desc)
                //计算前15位数值 组合内数字的次数
                combinationItemBean.countPre15 = getCombinationCount(pre15Str, tagEnums.desc)
                //计算过滤后前customScreenOutPre位后所有数值 组合内数字的次数
                combinationItemBean.countOutPre15 =
                    getCombinationCount(screenOutPreStr, tagEnums.desc)
                //计算限制自定义分析长度的所有数值 组合内数字的次数
                combinationItemBean.countLimit1 = getCombinationCount(limitStr1, tagEnums.desc)
                //计算限制数量统计的所有数值 组合内数字的次数
                combinationItemBean.countLimit2 = getCombinationCount(limitStr2, tagEnums.desc)
                AwLog.d("appendCombinationTrendsToRecyclerView combinationItemBean: $combinationItemBean")
                mAllCalAnalaysisCombinationList.add(combinationItemBean)
            }
        }
    }

    /**
     * 每种走势展示
     *
     * @param strList 每种走势字符串集合（顺顺顺跳跳顺。。。。。）
     */
    private fun appendEveryTrend(strList: MutableList<String?>, indexList: MutableList<Int>) {
        if (AwDataUtil.isEmpty(strList)) {
            return
        }
        for (i in strList.indices) {
            var serialNumber = i
            val str = strList[i]
            if (AwDataUtil.isEmpty(str)) {
                continue
            }
            if (!AwDataUtil.isEmpty(indexList)) {
                serialNumber = indexList[i]
            }
            appendCommon(
                matcherSearchText(
                    resources.getColor(R.color.black),
                    "走势" + (serialNumber + 1) + "：",
                    "走势" + (serialNumber + 1) + "：",
                    true
                )
            )
            appendCommon(
                matcherSearchText(
                    resources.getColor(com.aw.baselib.R.color.red),
                    str!!,
                    arrayOf("跳", "B"),
                    true
                )
            )
            appendCommon("\n")
            var countStr = str
            if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT1) {
                if (str.length > AppCacheUtil.getAnalysisLengthCustom()) {
                    //开启了限制统计数量长度， 并且当前已有数值长度大于自定义设置的数量
                    countStr = str.substring(
                        str.length - AppCacheUtil.getAnalysisLengthCustom(),
                        str.length
                    )
                }
            } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT2) {
                if (str.length > AppCacheUtil.getLimitStatisticsCountCustom()) {
                    //开启了限制统计数量长度， 并且当前已有数值长度大于自定义设置的数量
                    countStr = str.substring(
                        str.length - AppCacheUtil.getLimitStatisticsCountCustom(),
                        str.length
                    )
                }
            }
            appendStatistics(
                matcherSearchText(
                    getBetterColor(
                        mActivity, countOccurrences(
                            countStr, "跳"
                        ), countOccurrences(countStr, "顺")
                    ), "跳数：", "跳数：", judgeGreater(
                        countStr, "跳", "顺"
                    )
                )
            )
            appendStatistics(countOccurrences(countStr, "跳").toString() + "个")
            appendStatistics("\n")
            appendStatistics(
                matcherSearchText(
                    getBetterColor(
                        mActivity, countOccurrences(
                            countStr, "顺"
                        ), countOccurrences(countStr, "跳")
                    ), "顺数：", "顺数：", judgeGreater(
                        countStr, "顺", "跳"
                    )
                )
            )
            appendStatistics(countOccurrences(countStr, "顺").toString() + "个")
            appendStatistics("\n")
        }
        if (AppCacheUtil.isStatisticsCountMax()) {
            appendCommon(
                matcherSearchText(
                    resources.getColor(com.aw.baselib.R.color.red),
                    "Max：",
                    "Max：",
                    true
                )
            )
            appendCommon(
                matcherSearchText(
                    resources.getColor(com.aw.baselib.R.color.red),
                    getEveryJumpSmoothlyMaxCountStr(strList as MutableList<String>),
                    arrayOf(
                        "顺1",
                        "顺2",
                        "顺3",
                        "顺4",
                        "顺5",
                        "顺6",
                        "跳1",
                        "跳2",
                        "跳3",
                        "跳4",
                        "跳5",
                        "跳6"
                    ),
                    true
                )
            )
            appendCommon("\n")
        }
    }

    override fun onBackPressed() {
        //        AwThirdAppJudgeUtil.toDesktop(mActivity);
        System.arraycopy(mHits, 1, mHits, 0, mHits.size - 1)
        mHits[mHits.size - 1] = SystemClock.uptimeMillis()
        if (mHits[0] >= SystemClock.uptimeMillis() - 2000) {
            finish()
            ExitAppForced()
        } else {
            showMsg("再次点击返回键退出应用")
        }
    }

    private fun checkAppUpdate(isInitCheck: Boolean) {
        PgyUpdateManager.register(mActivity, object : UpdateManagerListener() {
            override fun onUpdateAvailable(s: String) {
                AwLog.d("Update onUpdateAvailable: $s")
                val pgyUpdateBean =
                    AwJsonUtil.getInstance().fromJson(s, PGYUpdateBean::class.java) as PGYUpdateBean
                if (pgyUpdateBean.data != null) {
                    val currentVersion =
                        AwAppUtils.getAppVersionInfo(mActivity, TYPE_VERSION.TYPE_VERSION_NAME)
                    var compareVerson: String? = ""
                    compareVerson = if (pgyUpdateBean.data!!.isNeedForceUpdate) {
                        pgyUpdateBean.data!!.forceUpdateVersion
                    } else {
                        pgyUpdateBean.data!!.versionName
                    }
                    if (AwVersionUtil.compareVersions(currentVersion, compareVerson) > 0
                        || AwDataUtil.getIntValue(
                            AwAppUtils.getAppVersionInfo(
                                mActivity,
                                TYPE_VERSION.TYPE_VERSION_CODE
                            )
                        ) < pgyUpdateBean.data!!.versionCode
                    ) {
                        val updateBean = UpdateBean()
                        updateBean.appurl = pgyUpdateBean.data!!.downloadURL
                        updateBean.isForceRenew =
                            if (pgyUpdateBean.data!!.isNeedForceUpdate) "1" else "0"
                        updateBean.description = pgyUpdateBean.data!!.releaseNote
                        updateBean.appVersion = pgyUpdateBean.data!!.versionName
                        updateBean.appCode = pgyUpdateBean.data!!.versionCode.toString() + ""
                        AwUpdateUtil.getInstance(mActivity).handleUpdate(updateBean) {}
                    } else {
                        if (isInitCheck) {
                            return
                        }
                        showMsg("已是最新版")
                    }
                } else {
                    if (isInitCheck) {
                        return
                    }
                    showMsg("已是最新版")
                }
            }

            override fun onNoUpdateAvailable() {
                AwLog.d("Update 已是最新版")
                if (isInitCheck) {
                    return
                }
                showMsg("已是最新版")
            }
        })
    }

    override fun getMsgUnreadCountSuccess(result: String?) {
        postEvent(EventRefreshMsgUnreadCountType(result))
        MyApp.mUnreadMsgCount = AwDataUtil.getIntValue(result)
        if (AwDataUtil.getIntValue(result) > 0) {
            //存在未读站内信,红点标识
            mToolbar.setRightImg(R.drawable.icon_me_unread_black)
        } else {
            mToolbar.setRightImg(R.drawable.icon_me)
        }
    }

    /**
     * 投注后选择结果数字的view更新
     *
     * @param checkedResultNumBean
     */
    private fun setResultView(checkedResultNumBean: NumEncloseBean?) {
        for (item in mEncloseNumsList) {
            if (checkedResultNumBean == null) {
                item.isChecked = false
            } else {
                if (checkedResultNumBean.resultNumber == item.resultNumber) {
                    item.isChecked = true
                } else {
                    item.isChecked = false
                }
            }
        }
        mResultNumAdapter!!.notifyDataSetChanged()
    }

    /**
     * ...............................API LOOP START.......................
     */
    private fun loopUnreadMsg() {
        mDisposableUserInfo = Observable.interval(30, TimeUnit.SECONDS)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe { aLong: Long? -> mPresenter!!.getMsgUnreadCount() }
    }

    private fun cancelLoopUnreadMsg() {
        if (mDisposableUserInfo != null) {
            AwLog.d("****** cancelLoopUnreadMsg ******")
            mDisposableUserInfo!!.dispose()
        }
    }

    private fun startLoopUnreadMsg() {
        cancelLoopUnreadMsg()
        AwLog.d("****** startLoopUnreadMsg ******")
        loopUnreadMsg()
    }
    /**...............................API LOOP END....................... */
}